{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# source: http://iamtrask.github.io (modified)\n",
    "import numpy as np\n",
    "\n",
    "X_XOR = np.array([[0,0,1], [0,1,1], [1,0,1],[1,1,1]]) \n",
    "y_truth = np.array([[0,1,1,1]]).T\n",
    "np.random.seed(1)\n",
    "synapse_0 = 2*np.random.random((3,1)) - 1\n",
    "\n",
    "def sigmoid(x):\n",
    "    output = 1/(1+np.exp(-x))\n",
    "    return output\n",
    "def sigmoid_output_to_derivative(output):\n",
    "    return output*(1-output) \n",
    "\n",
    "for iter in range(10000):\n",
    "    layer_1 = sigmoid(np.dot(X_XOR, synapse_0))\n",
    "    layer_1_error = layer_1 - y_truth\n",
    "    layer_1_delta = layer_1_error * sigmoid_output_to_derivative(layer_1)\n",
    "    synapse_0_derivative = np.dot(X_XOR.T,layer_1_delta)\n",
    "    synapse_0 -= synapse_0_derivative\n",
    "\n",
    "print(\"Output After Training: \\n\", layer_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
